﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Mvc.StarterSite.Controllers;
using System.Web.Mvc;
using MvcEngine.Mvc.Models.ViewModels;
using MvcEngine.Blog.Models.Entities;
using MvcEngine.Blog.Repositories;
using MvcEngine.Core;
using MvcEngine.Blog.Filters;
using MvcEngine.Mvc.Filters;
using MvcEngine.Mvc;
using MvcEngine.Blog.Components.Extensions;
using MvcEngine.Mvc.Controllers;

namespace MvcEngine.Blog.StarterSite.Controllers
{
    public class BlogCategoryController : SubController
    {
        private IBlogCategoryRepository categoryRepository = null;

        public BlogCategoryController(IBlogCategoryRepository categoryRepository)
        {
            this.categoryRepository = categoryRepository;
        }

        public MvcEngineModel Index(Guid blogId)
        {
            IList<BlogCategory> categories = categoryRepository.GetAllWithPublishedPosts(blogId).ToList();
            if (categories.Count == 0)
            {
                return new MvcEngineModel() { ViewName = "Empty" };
            }
            return new MvcEngineModelList<BlogCategory>() { List = categories, ViewName = "Index" };
        }
    }
}
